<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let obj = {
        id: 1,
        name: "haha"
    };

    console.log(obj);
    obj.name = "张三";
    console.log(obj);
    for (let key in obj) {
        console.log(key);
    }
    delete obj.name;
    console.log(obj);

    Object.defineProperty(obj, "age", {
        configurable: false,
        value: 18,
        writable: true,
        enumerable: true
    });
    console.log(obj);
    delete obj.age;
    console.log(obj);
    //不允许重新定义
    // Object.defineProperty(obj, "age", {
    //     configurable: false,
    //     value: 20
    // });
    obj.age = 20;
    console.log(obj);
    for (let key in obj) {
        console.log(key);
    }

    Object.defineProperties(obj, {
        "nickName": {
            value: "leo",
            configurable: false,
            writable: false,
            enumerable: true
        },
        "hubby": {
            value: ["Java", "C++"],
            configurable: true,
            writable: true,
            enumerable: true
        }
    });
    for (let key in obj) {
        console.log(key);
    }

    let opd = Object.getOwnPropertyDescriptor(obj, "age");
    console.log(opd);
    console.log(Object.getOwnPropertyDescriptors(obj));

    //创建一个与obj对象一样对象
    let obj1 = Object.assign(obj);
    console.log(obj);
    console.log("------------------------------------")
    console.log(obj1);
    //将两对象中的属性和方法混合到另一个对象中去
    let target = {
        a: 1,
        b: "haha",
        c: function () {
            console.log(this.b);
        }
    }
    //将target对象和obj对象中的属性和值复制到另一个新的对象中
    let objMix = Object.assign(target, obj, {d: 2, a: 4});
    console.log(objMix);
    //assign：针对引用数据类型，只是浅复制
    objMix.hubby[0] = "JavaScript";
    console.log("------------------------------------")
    console.log(objMix.hubby);
    console.log(obj1.hubby);
    console.log(obj.hubby);

    console.log(Object.is(obj, obj1));
    console.log(obj === obj1);
    console.log(obj === objMix);
    console.log(target === objMix);
    console.log(Object.is(obj, objMix));
    let obj2 = Object.assign({}, obj);
    console.log(Object.is(obj, obj2));

    console.log(Object.is(NaN, NaN));
    console.log(NaN === NaN);

    let obj3 = Object.create(obj);
    console.log(obj3);
    console.log(obj3.age);
    console.log(obj3 === obj);
</script>
</body>
</html>